package com.yun.zf.system.security.handle;

import cn.hutool.http.ContentType;
import com.alibaba.fastjson.JSON;
import com.yun.zf.system.security.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class PasswordAuthenticationnSuccessHandler  implements AuthenticationSuccessHandler {

    @Autowired
    private TokenService tokenService;
    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        // 使用jwt管理，所以封装用户信息生成jwt响应给前端
        // String token = jwtTokenUtils.generateToken(((WxAppletAuthenticationToken)authentication).getUser().getOpendId());
     String result ="";
        httpServletResponse.setContentType(ContentType.JSON.toString());
        httpServletResponse.getWriter().write(JSON.toJSONString(result));
    }
}
